<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
    
  </div>
  <!-- 新增script标签 写 模板结构 定义id属性 -->
 <!--  <script id="tpl" type="text/html">
    <div>
      <h2>这是公共头部</h2>
    </div>
  </script> -->
  <template id="tpl">
    <div>
      <h2>这是公共头部</h2>
    </div>
  </template>
  <script src="./vue.js"></script>
  <script>
   
    Vue.component('CommonHead', {
      /* template: `
        <div>
          <h2>这是一个公共的头部</h2>  
          {{ msg }}
          {{ reverseMsg }}
          <button @click="changeMsg">按钮</button>
        </div>
      `, */
      template: '#tpl',
      data(){
        return {
          msg: '这是组件的数据'
        }
      },
      methods: {
        changeMsg(){
          this.msg = '值改变了';
        }
      },
      watch: {
        msg(val){
          console.log('msg改变了', val);
        }
      },
      computed: {
        reverseMsg(){
          return this.msg.split('').reverse().join('');
        }
      }
    });
    // 相当于定义一个 组件构造函数 VueComponent(继承Vue)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>